/*
 * Abstract   ：和普利管理后台js文件
 * Author     ：蔡应	
 * Time       ：2016年08月09日10:04:26
 */
 $(function(){
	/*
	 *	用户登录	
	 */
	if ( $('.admin-login')[0] ) {
	   fnAdminLogin();
	}
	function fnAdminLogin() {
	    $('.submit').click(function(){
	        fnSubmit();
	    });

	    $(document).keydown(function (event) {
	        if (event.keyCode == "13"){
	            fnSubmit();
	        };
	    });

	    function fnSubmit(){
	        if( $(".valid-form").Validform().check() == false ){
	            return;
	        };
	        var  layerindex = layer.load(1, {
                shade: [0.1,'#000'] //0.1透明度的白色背景
            });
	        var formData = $('.valid-form').serializeArray();
	       $.post(tp5_url+'ap/accountLog', formData, function(response){
	       		layer.close(layerindex);
	            if (response.code == '1002') {	
	                window.location.href =response.url;
	            }else{
	                $('#verification').val('');
	            	document.getElementById("target").click(); 
	                layer.msg(response.msg,{time: 1500});
	            }
	        }, 'json');
	    }
	}

 //定义图片文件名
var img_type = '';

//菜单添加
if($('.admin-menusAdd')[0]){
	img_type = 'admin_img';
	 fnAdminAddc();
}
 function fnAdminAddc(){
	  $('.submit').click(function(){
		  if( $(".valid-form").Validform().check() == false ){
	            return;
	      };
	      var formData = $('.valid-form').serializeArray();
	      $.get(tp5_url+'aptwo/menusAddData',formData,function(response){
	    	    layer.msg(response.msg,{time: 1500});
	            if (response.code == '11000') {
	                window.location.href = response.url;
	            }
	      },'json');
	  })
 }

//子菜单添加
if($('.admin-menusAdd-son')[0]){
	fnSonAdd();
}
function fnSonAdd(){
	  $('.submit').click(function(){
		  if( $(".valid-form").Validform().check() == false ){
	            return;
	      };
	      var formData = $('.valid-form').serializeArray();
	      $.post(tp5_url+'aptwo/sonmenusAddData',formData,function(response){
	    	    layer.msg(response.msg,{time: 1500});
	            if (response.code == '11000') {
	                window.location.href = response.url;
	            }
	      },'json');
	  })
}

//菜单删除
if($('.sonmenus-data')[0]){
	 fnSonDelete();

}

function fnSonDelete(){
	$('.sonmenus-delete').click(function(){
          var admin_menu_id=$(this).attr('value');
	      $.get(tp5_url+'aptwo/sonmenusDelete',{'admin_menu_id':admin_menu_id},function(response){
	    	    layer.msg(response.msg,{time: 1500});
	            if (response.code == '11000') {
	            	 window.location.reload();
	            }
	      },'json');
	  })
}

//三级功能
if($('.admin-function')[0]){
	fnfunctionAdd();
}

function fnfunctionAdd(){
	$('.submit').click(function(){
		  if( $(".valid-form").Validform().check() == false ){
	            return;
	      };
	      var formData = $('.valid-form').serializeArray();
	      $.get(tp5_url+'aptwo/functionData',formData,function(response){
	    	    layer.msg(response.msg,{time: 1500});
	            if (response.code == '11000') {
	                window.location.href = response.url;
	            }
	      },'json');
	  })
}

//三级功能删除
if($('.fundtails-delete')[0]){
	fnFudeteDetele();
}
function fnFudeteDetele(){
	$('.function-ldes').click(function(){
	      var admin_function_id = $(this).attr('value');
	      $.get(tp5_url+'aptwo/funDetele',{'admin_function_id':admin_function_id},function(response){
	    	    layer.msg(response.msg,{time: 1500});
	            if (response.code == '11000') {
	            	 window.location.reload();
	            }
	      },'json');
	  })
}

//管理员添加
if($('.add-author')[0]){
	 fnAdminAdd();
}
function fnAdminAdd(){
	  $('.submit').click(function(){
		  if( $(".valid-form").Validform().check() == false ){
	            return;
	      };
	      var formData = $('.valid-form').serializeArray();
	      $.post(tp5_url+'aptwo/adminAdd',formData,function(response){
	    	    layer.msg(response.msg,{time: 1500});
	            if (response.code == '11000') {
	                window.location.href = response.url;
	            }
	      },'json');
	  })
}


//管理员删除
if($('.admit-index')[0]){
	 fnAdmitDelete();
}

function fnAdmitDelete(){

		$('.admin-delete').click(function(){
          var admin_id=$(this).attr('value');
	          layer.confirm('您确定要删除吗？', {
				  btn: ['确认',"取消"] //按钮
			  }, function(){
				    $.get(tp5_url+'aptwo/adminDelete',{'admin_id':admin_id},function(response){
	    	    layer.msg(response.msg,{time: 1500});
	            if (response.code == '11000') {
	            	 window.location.reload();
	            	}
	      		},'json');
			  });
	     });
}

//管理员密码修改
if($('.changepassword-save')[0]){
	 fnAdmitSave();

}
function fnAdmitSave(){
	$('.submit').click(function(){
		  if( $(".valid-form").Validform().check() == false ){
	            return;
	      };
	      var formData = $('.valid-form').serializeArray();
	     $.get(tp5_url+'aptwo/adminChange',formData,function(response){
	    	    layer.msg(response.msg,{time: 1500});
	            if (response.code == '11000') {
	                window.location.href = response.url;
	            }
	      },'json');
	  })
}

//权限分配
if($('.jurisdiction-add')[0]){
	$('.submitj').click(function(){
		var _detail_pic=Array();
		 $('input:checkbox[name="admin_function_id[]"]:checked').each(function(index,item){
   	         _detail_pic[index]=$(this).val();
   	     });
		var _list=Array();
		var admin_role_id=$('[name="admin_role_id"]').val();
		_list={
			'admin_function_id':_detail_pic,
			'admin_role_id':admin_role_id
		};
	     $.post(tp5_url+'aptwo/permissionDistribution',_list,function(response){
	    	    layer.msg(response.msg,{time: 1500});
	            if (response.code == '11000') {
	            	window.location.reload();
	            }
	      },'json');
	  });

	$("#select").click(function(){
        var inputs=$("input[name='admin_function_id[]']");
         if(this.checked){
           $(inputs).each(function(){this.checked=true;});
         }else{
           $(inputs).each(function(){this.checked=false;});
          }
   });



}


//角色新增
if($('.add-rolde')[0]){
	  $('.submit').click(function(){
		  if( $(".valid-form").Validform().check() == false ){
	            return;
	      };
	      var formData = $('.valid-form').serializeArray();
	      $.get(tp5_url+'aptwo/rolesHandle',formData,function(response){
	    	    layer.msg(response.msg,{time: 1500});
	            if (response.code == '11000') {
	                window.location.href = response.url;
	            }
	      },'json');
	  })
}
//角色删除
if($('.role-delete')[0]){
			$('.role-delete').click(function(){
          var role_id=$(this).attr('value');
	          layer.confirm('您确定要删除吗？', {
				  btn: ['确认',"取消"] //按钮
			  }, function(){
				    $.get(tp5_url+'aptwo/rolesDelete',{'role_id':role_id},function(response){
	    	    layer.msg(response.msg,{time: 1500});
	            if (response.code == '11000') {
	            	 window.location.reload();
	            	}
	      		},'json');
			  });
	     })
}


//文书类型 
if($('.writ-type')[0]){

	//新增与编辑
	$('.writ-tyupe-request').click(function(){
		  if( $(".valid-form").Validform().check() == false ){
	            return;
	      };
	      var  layerindex = layer.load(1, {
                shade: [0.1,'#000'] //0.1透明度的白色背景
            });
	      var formData = $('.valid-form').serializeArray();
	      $.get(tp5_url+'aptwo/writTyupeRequest',formData,function(response){
	      	 	layer.close(layerindex);
	    	    layer.msg(response.msg,{time: 1500});
	            if (response.code == '202') {
	                window.location.reload();
	            }
	      },'json');
	  });

	//编辑查询 
	 $('.writ-tyupe-edit').click(function(){
		 var writ_type_id=$(this).attr('value');
	     $.get(tp5_url+'front/writTypeFind',{'writ_type_id':writ_type_id},function(response){
	            if (response.code == '202') {
	                  $('[name="wt_name"]').val(response.data.wt_name);
	                  $('[name="wt_sort"]').val(response.data.wt_sort);
	                  $('[name="writ_type_id"]').val(response.data.writ_type_id);
	            }else{
	            	 layer.msg(response.msg,{time: 1500});
	            }
	     },'json');
	  });

	 //清空
	 $('.writ-type-remove').click(function(){
	 	$('[name="wt_name"]').val('');
	 	 $('[name="wt_sort"]').val('0');
	 	$('[name="writ_type_id"]').val('');
	 });

	 //删除分类
	 $('.writ-type-delete').click(function(){
          var writ_type_id=$(this).attr('value');
	          layer.confirm('您确定要删除吗？', {
				  btn: ['确认',"取消"] //按钮
			  }, function(){
		 	var  layerindex = layer.load(1, {
                shade: [0.1,'#000'] //0.1透明度的白色背景
            });
		    $.get(tp5_url+'aptwo/writTypeDelete',{'writ_type_id':writ_type_id},function(response){
	    	    layer.msg(response.msg,{time: 1500});
	    	    layer.close(layerindex);
	            if (response.code == '202') {
	            	 window.location.reload();
	            }
	      		},'json');
		   });
	})
}



//文书新增与编辑
if($('.writ-any')[0]){
		 img_type = 'writ';
}


//轮播图上传
if($('.slideshow-list')[0]){
	img_type = 'carousel';
	
		//新增与编辑
	$('.submit').click(function(){
		  if( $(".valid-form").Validform().check() == false ){
	            return;
	      };
	      var  layerindex = layer.load(1, {
                shade: [0.1,'#000'] //0.1透明度的白色背景
            });
	      var formData = $('.valid-form').serializeArray();
	      $.post(tp5_url+'aptwo/carouselImg',formData,function(response){
	      	 	layer.close(layerindex);
	    	    layer.msg(response.msg,{time: 1500});
	            if (response.code == '202') {
	                 window.location.reload();
	            }
	      },'json');
	  });

}

//文书
if($('.writ-list')[0]){

		//删除
		$('.writ-delete').click(function(){
          var writ_id=$(this).attr('value');
	          layer.confirm('您确定要删除吗？', {
				  btn: ['确认',"取消"] //按钮
			  }, function(){
			var  layerindex = layer.load(1, {
                shade: [0.1,'#000'] //0.1透明度的白色背景
            });
			  $.get(tp5_url+'aptwo/writDelete',{'writ_id':writ_id},function(response){
	    	    	layer.msg(response.msg,{time: 1500});
	    	    	 layer.close(layerindex);
		            if (response.code == '202') {
		            	 window.location.reload();
		            	}
		      		},'json');
			  });
	     });
		//操作
		$('.writ-send').click(function(){
          var writ_id=$(this).attr('value');
	          layer.confirm('您确定要操作吗？', {
				  btn: ['确认',"取消"] //按钮
			  }, function(){
			var  layerindex = layer.load(1, {
                shade: [0.1,'#000'] //0.1透明度的白色背景
            });
			  $.get(tp5_url+'aptwo/writAnnounce',{'writ_id':writ_id},function(response){
	    	    	layer.msg(response.msg,{time: 1500});
	    	    	 layer.close(layerindex);
		            if (response.code == '202') {
		            	 window.location.reload();
		            	}
		      		},'json');
			  });
	     });	

}


//律师展示新增与编辑
if($('.lawyer-add')[0]){
		img_type = 'lawyer';
	//新增与编辑
	$('.submit').click(function(){
		  if( $(".valid-form").Validform().check() == false ){
	            return;
	      };
	      var  layerindex = layer.load(1, {
                shade: [0.1,'#000'] //0.1透明度的白色背景
            });
	      var formData = $('.valid-form').serializeArray();
	      $.post(tp5_url+'aptwo/lawyerPresent',formData,function(response){
	      	 	layer.close(layerindex);
	    	    layer.msg(response.msg,{time: 1500});
	            if (response.code == '202') {
	                 window.location.href = response.url;
	            }
	      },'json');
	  });
}
//律师删除 
if($('.lawyer-list')[0]){
		$('.lawyer-delete').click(function(){
          var lawyer_id=$(this).attr('value');
	          layer.confirm('您确定要删除吗？', {
				  btn: ['确认',"取消"] //按钮
			  }, function(){
			var  layerindex = layer.load(1, {
                shade: [0.1,'#000'] //0.1透明度的白色背景
            });
			  $.get(tp5_url+'aptwo/lawyerDelet',{'lawyer_id':lawyer_id},function(response){
	    	    	layer.msg(response.msg,{time: 1500});
	    	    	 layer.close(layerindex);
		            if (response.code == '202') {
		            	 window.location.reload();
		            	}
		      		},'json');
			  });
	     })
}


//咨询类型
if($('.consul-type')[0]){
	 //清空
	 $('.consul-type-remove').click(function(){
	 	$('[name="ct_name"]').val('');
	 	$('[name="ct_sort"]').val('0');
	 	$('[name="consult_type_id"]').val('');
	 });


	 //新增与编辑
	$('.consul-tyupe-request').click(function(){
		  if( $(".valid-form").Validform().check() == false ){
	            return;
	      };
	      var  layerindex = layer.load(1, {
                shade: [0.1,'#000'] //0.1透明度的白色背景
            });
	      var formData = $('.valid-form').serializeArray();
	      $.get(tp5_url+'aptwo/consulTyupeRequest',formData,function(response){
	      	 	layer.close(layerindex);
	    	    layer.msg(response.msg,{time: 1500});
	            if (response.code == '202') {
	                window.location.reload();
	            }
	      },'json');
	  });

	//编辑查询 
	 $('.consul-tyupe-edit').click(function(){
		 var consult_type_id=$(this).attr('value');
	     $.get(tp5_url+'consul/consulTypeFind',{'consult_type_id':consult_type_id},function(response){
	            if (response.code == '202') {
	                  $('[name="ct_name"]').val(response.data.ct_name);
	                  $('[name="ct_sort"]').val(response.data.ct_sort);
	                  $('[name="consult_type_id"]').val(response.data.consult_type_id);
	            }else{
	            	 layer.msg(response.msg,{time: 1500});
	            }
	     },'json');
	  });

	 //删除分类
	 $('.consul-type-delete').click(function(){
          var consult_type_id=$(this).attr('value');
	          layer.confirm('您确定要删除吗？', {
				  btn: ['确认',"取消"] //按钮
			  }, function(){
			 layer.load(1, {
  			  shade: [0.1,'#000'] //0.1透明度的白色背景
		  	 });
		    $.get(tp5_url+'aptwo/consulTypeDelete',{'consult_type_id':consult_type_id},function(response){
	    	    layer.msg(response.msg,{time: 1500});
	            if (response.code == '202') {
	            	 window.location.reload();
	            	}
	      		},'json');
		   });
	})

}

//咨询列表
if($('.consult-list')[0]){
	    //操作
	    $('.consul-handle').click(function(){
					var consult_id=$(this).attr('value');
					var state=$(this).attr('name');
					var title = '';
					if(state == 1){
						title = '您确定要解除禁止吗?';		
					}else{
						title = '您确定要禁止吗?';	
					}
			          layer.confirm(title, {
						  btn: ['确认',"取消"] //按钮
					  }, function(){
					 layer.load(1, {
		  			  shade: [0.1,'#000'] //0.1透明度的白色背景
				  	 });
				    $.get(tp5_url+'aptwo/consulHandle',{'consult_id':consult_id,'state':state},function(response){
			    	    layer.msg(response.msg,{time: 1500});
			            if (response.code == '202') {
			            	 window.location.reload();
			            	}
			      		},'json');
				   });
	    });

	    	//搜索
	    $('.consult-search').click(function(){
	    	  	$("#transmit").attr('action',tp5_url+'consul/consult_list');
	    		$('#transmit').submit();
	    });
	    //导出表格
	     $('.consult-table').click(function(){
	    	  	$("#transmit").attr('action',tp5_url+'aptwo/consulTable');
	    		$('#transmit').submit();
	    });	

}


//短信推送设置
if($('.consul-sie')[0]){
		 //清空
	 $('.consul-type-remove').click(function(){
	 	$('[name="a_username"]').val('');
	 	/*$('[name="consult_push_sie_id"]').val('');*/
	 });


	//新增与编辑
	$('.consul-tyupe-request').click(function(){
		  if( $(".valid-form").Validform().check() == false ){
	            return;
	      };
	      var  layerindex = layer.load(1, {
                shade: [0.1,'#000'] //0.1透明度的白色背景
            });
	      var formData = $('.valid-form').serializeArray();
	      $.get(tp5_url+'aptwo/consulPushRequest',formData,function(response){
	      	 	layer.close(layerindex);
	    	    layer.msg(response.msg,{time: 1500});
	            if (response.code == '202') {
	                window.location.reload();
	            }
	      },'json');
	  });

	 //删除
	 $('.consul-sie-delete').click(function(){
 		var consult_push_sie_id=$(this).attr('value');
	          layer.confirm('您确定要删除吗？', {
				  btn: ['确认',"取消"] //按钮
			  }, function(){
			var  layerindex = layer.load(1, {
                shade: [0.1,'#000'] //0.1透明度的白色背景
            });
		    $.get(tp5_url+'aptwo/consulPushDelete',{'consult_push_sie_id':consult_push_sie_id},function(response){
		    	layer.close(layerindex);
	    	    layer.msg(response.msg,{time: 1500});
	            if (response.code == '202') {
	            	 window.location.reload();
	            	}
	      		},'json');
		   });

	 });

}

//待回复咨询
if($('.me-consult')[0]){

	 $('.consul-type-remove').click(function(){
	 	$('[name="a_username"]').val('');
	 /*	$('[name="consult_push_sie_id"]').val('');*/
	 });
	//查询
	 $('.me-reply').click(function(){
		 var consult_id=$(this).attr('value');
	     $.get(tp5_url+'consul/meReplsyFind',{'consult_id':consult_id},function(response){
	            if (response.code == '202') {
	                  $('#ct_details').html(response.data);
	                  $('[name="consult_id"]').val(consult_id);
	            }else{
	            	 layer.msg(response.msg,{time: 1500});
	            }
	     },'json');
	  });

	 //回复
	 $('.consul-me-request').click(function(){
		  if( $(".valid-form").Validform().check() == false ){
	            return;
	      };
	      var  layerindex = layer.load(1, {
                shade: [0.1,'#000'] //0.1透明度的白色背景
            });
	      var formData = $('.valid-form').serializeArray();
	      $.post(tp5_url+'aptwo/meConsulRequest',formData,function(response){
	      	 	layer.close(layerindex);
	    	    layer.msg(response.msg,{time: 1500});
	            if (response.code == '202') {
	                window.location.reload();
	            }
	      },'json');
	  });
	 
}

//咨讯类型
if($('.news-type')[0]){
	
	//新增与编辑
	$('.writ-tyupe-request').click(function(){
		  if( $(".valid-form").Validform().check() == false ){
	            return;
	      };
	      var  layerindex = layer.load(1, {
                shade: [0.1,'#000'] //0.1透明度的白色背景
            });
	      var formData = $('.valid-form').serializeArray();
	      $.get(tp5_url+'aptwo/newsTypeRequest',formData,function(response){
	      	 	layer.close(layerindex);
	    	    layer.msg(response.msg,{time: 1500});
	            if (response.code == '202') {
	                window.location.reload();
	            }
	      },'json');
	  });

	//编辑查询 
	 $('.writ-tyupe-edit').click(function(){
		 var news_type_id=$(this).attr('value');
	     $.get(tp5_url+'front/newsTypeFind',{'news_type_id':news_type_id},function(response){
	            if (response.code == '202') {
	                  $('[name="nt_name"]').val(response.data.nt_name);
	                  $('[name="nt_sort"]').val(response.data.nt_sort);
	                  $('[name="news_type_id"]').val(response.data.news_type_id);
	            }else{
	            	 layer.msg(response.msg,{time: 1500});
	            }
	     },'json');
	  });

	 //清空
	 $('.writ-type-remove').click(function(){
	 	$('[name="nt_name"]').val('');
	 	$('[name="nt_sort"]').val('0');
	 	$('[name="news_type_id"]').val('');
	 });

	 //删除分类
	 $('.writ-type-delete').click(function(){
          var news_type_id=$(this).attr('value');
	          layer.confirm('您确定要删除吗？', {
				  btn: ['确认',"取消"] //按钮
			  }, function(){
			 layer.load(1, {
  			  shade: [0.1,'#000'] //0.1透明度的白色背景
		  	 });
		    $.get(tp5_url+'aptwo/newsTypeDelete',{'news_type_id':news_type_id},function(response){
	    	    layer.msg(response.msg,{time: 1500});
	            if (response.code == '202') {
	            	 window.location.reload();
	            	}
	      		},'json');
		   });
	})	
}

//资讯
if($('.news-list')[0]){
	//删除
	 $('.news-delete').click(function(){
	 
 		var news_id=$(this).attr('value');
	          layer.confirm('您确定要删除吗？', {
				  btn: ['确认',"取消"] //按钮
			  }, function(){
			var  layerindex = layer.load(1, {
                shade: [0.1,'#000'] //0.1透明度的白色背景
            });
		    $.get(tp5_url+'aptwo/newsDelete',{'news_id':news_id},function(response){
		    	layer.close(layerindex);
	    	    layer.msg(response.msg,{time: 1500});
	            if (response.code == '202') {
	            	 window.location.reload();
	            	}
	      		},'json');
		   });

	 });


	 //操作发布
		$(".news-send").click(function(){
			var news_id=$(this).attr('value');
	          layer.confirm('您确定要操作吗？', {
				  btn: ['确认',"取消"] //按钮
			  }, function(){
			var  layerindex = layer.load(1, {
                shade: [0.1,'#000'] //0.1透明度的白色背景
            });
		    $.get(tp5_url+'aptwo/newsIssue',{'news_id':news_id},function(response){
		    	layer.close(layerindex);
	    	    layer.msg(response.msg,{time: 1500});
	            if (response.code == '202') {
	            	 window.location.reload();
	            	}
	      		},'json');
		   });
		})
}

//新闻
if($('.news-add')[0]){
	img_type = 'news';

	$('.submit-news').click(function(){
		 //新增与编辑
 		if( $(".valid-form").Validform().check() == false ){
	            return;
	      };
	      var  layerindex = layer.load(1, {
                shade: [0.1,'#000'] //0.1透明度的白色背景
            });
	      var formData = $('.valid-form').serializeArray();
	      $.post(tp5_url+'aptwo/newsAnyRequest',formData,function(response){
	      	 	layer.close(layerindex);
	    	    layer.msg(response.msg,{time: 1500});
	           if (response.code == '202') {
	                 window.location.href = response.url;
	            }
	      },'json');
	  });
}

//顾问卡
if($('.counselor-any')[0]){
		$('.submit').click(function(){
		 //新增与编辑
 		if( $(".valid-form").Validform().check() == false ){
	            return;
	      };
	      var  layerindex = layer.load(1, {
                shade: [0.1,'#000'] //0.1透明度的白色背景
            });
	      var formData = $('.valid-form').serializeArray();
	      $.post(tp5_url+'aptwo/counselorAnyRequest',formData,function(response){
	      	 	layer.close(layerindex);
	    	    layer.msg(response.msg,{time: 1500});
	           if (response.code == '202') {
	                 window.location.href = response.url;
	            }
	      },'json');
	  });
}
if($('.counselor-list')[0]){
			//删除
	 $('.counselor-delete').click(function(){
	 
 		var counselor_id=$(this).attr('value');
	          layer.confirm('您确定要删除吗？', {
				  btn: ['确认',"取消"] //按钮
			  }, function(){
			var  layerindex = layer.load(1, {
                shade: [0.1,'#000'] //0.1透明度的白色背景
            });
		    $.get(tp5_url+'aptwo/counselorDelete',{'counselor_id':counselor_id},function(response){
		    	layer.close(layerindex);
	    	    layer.msg(response.msg,{time: 1500});
	            if (response.code == '202') {
	            	 window.location.reload();
	            	}
	      		},'json');
		   });

	 });
}

//订单
if($('.orders-detail')[0]){
		
	 $('.orders-orderHandle').click(function(){
	 
 		var state=$(this).attr('value');
 		var order_id = $('[name="order_id"]').val();
	          layer.confirm('您确定要操作吗？', {
				  btn: ['确认',"取消"] //按钮
			  }, function(){
			var  layerindex = layer.load(1, {
                shade: [0.1,'#000'] //0.1透明度的白色背景
            });
		    $.get(tp5_url+'aptwo/orderHandle',{'order_id':order_id,'state':state},function(response){
		    	layer.close(layerindex);
	    	    layer.msg(response.msg,{time: 1500});
	            if (response.code == '202') {
	            	 window.location.reload();
	            	}
	      		},'json');
		   });
	 });	
}
//订单导出表格
if($('.order-list')[0]){
		//搜索
	    $('.consult-search').click(function(){
	    	  	$("#transmit").attr('action',tp5_url+'order/order_list');
	    		$('#transmit').submit();
	    });
	    //导出表格
	     $('.order-tabale').click(function(){
	    	  	$("#transmit").attr('action',tp5_url+'aptwo/orderTable');
	    		$('#transmit').submit();
	    });

}

//服务
if($('.orders-serve-detail')[0]){
	 $('.orders-orderHandle').click(function(){
	 
 		var state=$(this).attr('value');
 		var counselor_order_id = $('[name="counselor_order_id"]').val();
 		var co_age_limit   = $('[name="co_age_limit"]').val();
	          layer.confirm('您确定要操作吗？', {
				  btn: ['确认',"取消"] //按钮
			  }, function(){
			var  layerindex = layer.load(1, {
                shade: [0.1,'#000'] //0.1透明度的白色背景
            });
		    $.get(tp5_url+'aptwo/serveHandle',{'counselor_order_id':counselor_order_id,'state':state,'co_age_limit':co_age_limit},function(response){
		    	layer.close(layerindex);
	    	    layer.msg(response.msg,{time: 1500});
	            if (response.code == '202') {
	            	 window.location.reload();
	            	}
	      		},'json');
		   });
	 });
}

//新增服务
if($('.serve-any')[0]){
	$('.submit').click(function(){
		 //新增与编辑
 		if( $(".valid-form").Validform().check() == false ){
	            return;
	      };
	      var  layerindex = layer.load(1, {
                shade: [0.1,'#000'] //0.1透明度的白色背景
            });
	      var formData = $('.valid-form').serializeArray();
	      $.post(tp5_url+'aptwo/serveAnyRequest',formData,function(response){
	      	 	layer.close(layerindex);
	    	    layer.msg(response.msg,{time: 1500});
	           if (response.code == '202') {
	                 window.location.href = response.url;
	            }
	      },'json');
	  });
}

//用户
if($('.user-list')[0]){
		//搜索
	    $('.user-search').click(function(){
	    	  	$("#transmit").attr('action',tp5_url+'auser/user_list');
	    		$('#transmit').submit();
	    });
	    //导出表格
	     $('.user-table').click(function(){
	    	  	$("#transmit").attr('action',tp5_url+'aptwo/userTable');
	    		$('#transmit').submit();
	    });	
}

	/*
	 *	Common
	 */

	// icheck
	// $('.i-checks').iCheck({
 //        checkboxClass: 'icheckbox_square-green',
 //        radioClass: 'iradio_square-green',
 //    });

	// 时间选择
	if ( $(".clockpicker")[0] ){
		$('.clockpicker').clockpicker()
		    .find('input').change(function(){
		        // TODO：时间改变
		        console.log(this.value);
		    });
		$('#demo-input').clockpicker({
		    autoclose: true
		});
		if (something) {
		    // 手动操作（clockpicker初始化之后）
		    $('#demo-input').clockpicker('show') //或者隐藏，删除...
		         	.clockpicker('toggleView', 'minutes');
		}
	};

	//表单验证
	if ($(".valid-form")[0]) {
		$('.valid-form').Validform({
		    tiptype: 3, // tiptype:3，提示信息显示在当前校验元素的兄弟节点(siblings)
		    // ignoreHidden:true,
		    showAllError: true
		});
	};




	// 开始结束日期
	if ($("#timedStart")[0]){
	    fnStartEndTimed();
	};
	function fnStartEndTimed(){
	    var start = {
	        elem: '#timedStart',
	        format: 'YYYY/MM/DD',
	        // min: laydate.now(), //设定最小日期为当前日期
	        max: '2099-06-16 23:59:59', //最大日期
	        istime: true,
	        istoday: false,
	        choose: function(datas){
	             end.min = datas; //开始日选好后，重置结束日的最小日期
	             end.start = datas //将结束日的初始值设定为开始日
	        }
	    };
	    var end = {
	        elem: '#timedEnd',
	        format: 'YYYY/MM/DD',
	        // min: laydate.now(),
	        max: '2099-06-16 23:59:59',
	        istime: true,
	        istoday: false,
	        choose: function(datas){
	            start.max = datas; //结束日选好后，重置开始日的最大日期
	        }
	    };
	    laydate(start);
	    laydate(end);
	}

	// 开始结束日期_当前时间算起
	if ($("#timeStart")[0]){
	    fnStartEndTime();
	};
	function fnStartEndTime(){
	    var start = {
	        elem: '#timeStart',
	        format: 'YYYY/MM/DD hh:mm:ss',
	        min: laydate.now(), //设定最小日期为当前日期
	        max: '2099-06-16 23:59:59', //最大日期
	        istime: true,
	        istoday: false,
	        choose: function(datas){
	             end.min = datas; //开始日选好后，重置结束日的最小日期
	             end.start = datas //将结束日的初始值设定为开始日
	        }
	    };
	    var end = {
	        elem: '#timeEnd',
	        format: 'YYYY/MM/DD hh:mm:ss',
	        min: laydate.now(),
	        max: '2099-06-16 23:59:59',
	        istime: true,
	        istoday: false,
	        choose: function(datas){
	            start.max = datas; //结束日选好后，重置开始日的最大日期
	        }
	    };
	    laydate(start);
	    laydate(end);
	}

	// 文本编辑器
	if ( $('#editor')[0] ){
		fnUeditor();
	};
	function fnUeditor(){
		 var ue = UE.getEditor('editor',{
                    autoHeight:true,
                    initialFrameHeight: 450
            });
	}
	if ( $('#editor02')[0] ){
		fnUeditor02();
	};
	function fnUeditor02(){
		 var ue02 = UE.getEditor('editor02',{
                    autoHeight:true,
                    initialFrameHeight: 450
            });
	}
	if ( $('#editor03')[0] ){
		fnUeditor03();
	};
	function fnUeditor03(){
		 var ue03 = UE.getEditor('editor03',{
                    autoHeight:true,
                    initialFrameHeight: 450
            });
	}

	if ( $('#editor04')[0] ){
		fnUeditor04();
	};
	function fnUeditor04(){
		 var ue03 = UE.getEditor('editor04',{
                    autoHeight:true,
                    initialFrameHeight: 450
            });
	}
	// 文本编辑器
	// if ( $('.ueditor')[0] ){
	// 	fnUeditors();
	// };
	// function fnUeditors(){
	// 	var ue = [];
	// 	for(var i=0; i<$('.ueditor').length ; i++){
	// 		ue[i] = UE.getEditor('editor0'+i,{
 //                    autoHeight:true,
 //                    initialFrameHeight: 600
 //            });
	// 	}

	// }



    // 图片上传
    if ( $('.upload-pic')[0] ){
		for (var i = 0; i<$(".upload-pic").length ; i++ ) {
			fnUploadPic(i);
		};
	};
	function fnUploadPic(a){
	    var $ = jQuery,
	        $list = $('.upload-pic').eq(a),
	        // 优化retina, 在retina下这个值是2
	        ratio = window.devicePixelRatio || 1,
	        thumpSize = $list.find(".pic-url").attr("size"),
	        // 缩略图大小
	        thumbnailWidth = thumpSize.split(",")[0],
	        thumbnailHeight = thumpSize.split(",")[1],
	        // Web Uploader实例
	        uploader;

	    // 初始化Web Uploader
	    uploader = WebUploader.create({
	        // 自动上传。
	        auto: true,
	        // swf文件路径
	        // swf文件路径
	        swf: purl+'/Api/webuploader/Uploader.swf' ,
	        // 文件接收服务端。
	        server: tp5_url+'ap/imgUploads',
	        // 选择文件的按钮。可选。
	        // 内部根据当前运行是创建，可能是input元素，也可能是flash.
	        pick: $('.upload-btn').eq(a),
	        // 只允许选择文件，可选。
	        accept: {
	            title: 'Images',
	            extensions: 'gif,jpg,jpeg,bmp,png',
	            mimeTypes: 'image/*'
	        },
	        thump: {
			    width: thumbnailWidth,
			    height: thumbnailHeight,
			    // 图片质量，只有type为`image/jpeg`的时候才有效。
			    quality: 90,
			    // 是否允许放大，如果想要生成小图的时候不失真，此选项应该设置为false.
			    allowMagnify: false,
			    // 是否允许裁剪。
			    crop: false,
			    // 为空的话则保留原有图片格式。
			    // 否则强制转换成指定的类型。
			    type: 'image/jpeg'
			}
	    });

		uploader.option('formData',{
			  imgtype:img_type,
		});
	    // 当有文件添加进来的时候
	    uploader.on( 'fileQueued', function( file ) {
	        // 创建缩略图
	        uploader.makeThumb( file, function( error, src ) {
	            if ( error ) {
	                $list.find('img').replaceWith('<span>不能预览</span>');
	                return;
	            }

	            $list.find('img').attr( 'src', src );
	        }, thumbnailWidth, thumbnailHeight );
	    });
	  
	    // 文件上传过程中创建进度条实时显示。
	    uploader.on( 'uploadProgress', function( file, percentage ) {
	        var $li = $( '#'+file.id ),
	            $percent = $li.find('.progress span');
	        // 避免重复创建
	        if ( !$percent.length ) {
	            $percent = $('<p class="progress"><span></span></p>')
	                    .appendTo( $li )
	                    .find('span');
	        }

	        $percent.css( 'width', percentage * 100 + '%' );
	    });
	        // 文件上传成功，给item添加成功class, 用样式标记上传成功。
	    uploader.on( 'uploadSuccess', function( file,response ) {
			layer.msg(response.msg,{time: 1500});
	    	if(response.code == '101'){
				$list.find('img').attr( 'src', purl+'/Images/img.jpg');
				$list.find(".pic-url").val("");
	    	}else{
		        $list.find(".pic-url").val(response.url);
		        $( '#'+file.id ).addClass('upload-state-done');
		        // 文件删除
			    $list.on('click', '.delete-pic-btn', function() {
			    	console.log(2);
				    uploader.removeFile( file );
				    $list.find('img').attr( 'src', purl+'/Images/img.jpg');
					var vale = '';
					$list.find(".pic-url").val(vale);
				})
	    	}
	    });
	    $list.on('click', '.delete-pic-btn', function() {
			$list.find('img').attr( 'src', purl+'/Images/img.jpg');
			var vale = '';
			$list.find(".pic-url").val(vale);
		});
	    // 文件上传失败，现实上传出错。
	    uploader.on( 'uploadError', function( file ) {
	        var $li = $( '#'+file.id ),
	            $error = $li.find('div.error');

	        // 避免重复创建
	        if ( !$error.length ) {
	            $error = $('<div class="error"></div>').appendTo( $li );
	        }

	        $error.text('上传失败');
	    });

	    // 完成上传完了，成功或者失败，先删除进度条。
	    uploader.on( 'uploadComplete', function( file ) {
	        $( '#'+file.id ).find('.progress').remove();
	    });
    }

})

